1 using UnityEngine;
2
3 namespace
ProceduralToolkit.Examples
4 {
5     
public static class Backs
6     {
7         
public static MeshDraft Back0(Vector3 center, float width, float length, float height)
8         {
9             
var draft = MeshDraft.Hexahedron(width, length, height);
10             draft.Move(center + Vector3.up*height/
2);
11             
return draft;
12         }
13
14         
public static MeshDraft Back1(Vector3 center, float width, float length, float height)
15         {
16             
var draft = new MeshDraft();
17             
int plankCount = Random.Range(1, 5);
18             
float plankStep = height/plankCount;
19             
float plankHeight = plankStep*Random.Range(0.3f, 0.8f);
20             
float plankWidth = width - length*2;
21
22             
float offeset = 0;
23             
if (plankCount > 1)
24             {
25                 offeset = RandomE.Range(
0, (plankStep - plankHeight)/2, 3);
26             }
27             Vector3 startPosition = Vector3.up*(-height/
2 + plankStep - plankHeight/2 - offeset);
28             
for (int i = 0; i < plankCount; i++)
29             {
30                 
var plank = MeshDraft.Hexahedron(plankWidth, length, plankHeight);
31                 plank.Move(startPosition + Vector3.up*i*plankStep);
32                 draft.Add(plank);
33             }
34             
var rod = MeshDraft.Hexahedron(length, length, height);
35             rod.Move(Vector3.left*(width/
2 - length/2));
36             draft.Add(rod);
37             rod.Move(Vector3.right*(width - length));
38             draft.Add(rod);
39             draft.Move(center + Vector3.up*height/
2);
40             
return draft;
41         }
42
43         
public static MeshDraft RodBack(Vector3 center, float width, float length, float height)
44         {
45             
var draft = new MeshDraft();
46             
int rodCount = Random.Range(1, 5);
47             
float maxWidth = (width - length*2)/rodCount;
48             
float rodWidth = RandomE.Range(maxWidth/4, maxWidth*3/4, 3);
49             
float interval = (width - length*2 - rodWidth*rodCount)/(rodCount + 1);
50             
float upperRodHeight = Mathf.Min(height*3/4, length*Random.Range(1, 4));
51             
float rodHeight = height - upperRodHeight;
52
53             
var leftRod = MeshDraft.Hexahedron(length, length, rodHeight);
54             leftRod.Move(Vector3.left*(width - length)/
2 + Vector3.down*upperRodHeight/2);
55             draft.Add(leftRod);
56             leftRod.Move(Vector3.right*(width - length));
57             draft.Add(leftRod);
58
59             Vector3 startPosition = Vector3.left*(width/
2 - length - interval - rodWidth/2) +
60                                     Vector3.down*upperRodHeight/
2;
61             
for (int i = 0; i < rodCount; i++)
62             {
63                 
var rod = MeshDraft.Hexahedron(rodWidth, length, rodHeight);
64                 rod.Move(startPosition + Vector3.right*i*(rodWidth + interval));
65                 draft.Add(rod);
66             }
67             
var upperRod = MeshDraft.Hexahedron(width, length, upperRodHeight);
68             upperRod.Move(Vector3.up*rodHeight/
2);
69             draft.Add(upperRod);
70             draft.Move(center + Vector3.up*height/
2);
71             
return draft;
72         }
73     }
74 }


Gõ tìm kiếm nhanh...